package com.example.practice;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.example.practice.adapter.ControllerSensorAdapter;
import com.example.practice.bean.SensorStatus;
import com.example.practice.bean.SensorValue;

public class ControllerActivity extends BaseActivity {
	GridView gridView;
	ControllerSensorAdapter controllerSensorAdapter;
	private List<SensorStatus> sensorStatus = new ArrayList<SensorStatus>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_controller);

		gridView = (GridView)findViewById(R.id.grid_view);
		controllerSensorAdapter = new ControllerSensorAdapter(sensorStatus);
		gridView.setAdapter(controllerSensorAdapter);
		
		update();
		
		gridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				sensorStatus.get(arg2).on = !sensorStatus.get(arg2).on;
				controllerSensorAdapter.notifyDataSetChanged();
			}
		});
	}

	private void update(){
		SensorStatus waterDump = new SensorStatus();
		waterDump.name = "ˮ��";
		waterDump.on = false;
		
		SensorStatus fan = new SensorStatus();
		fan.name = "������";
		fan.on = false;
		
		SensorStatus bee = new SensorStatus();
		bee.name = "����";
		bee.on = false;
		
		SensorStatus led = new SensorStatus();
		led.name = "LED";
		led.on = false;
		
		
		sensorStatus.add(bee);
		sensorStatus.add(fan);
		sensorStatus.add(waterDump);
		sensorStatus.add(led);
	}

	@Override
	protected void onGetSensorValue(SensorValue sensorValue) {
		// TODO Auto-generated method stub
		
	}

}
